package com.cuit.service.Impl;

import com.cuit.mapper.OrgMapper;
import com.cuit.params.OrgParams;
import com.cuit.pojo.Org;
import com.cuit.service.OrgService;
import com.cuit.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author SYE
 * @date 2023/7/27 16:46
 * @desciption:
 */
@Service
@Slf4j
public class OrgServiceImpl implements OrgService {

    @Autowired
    private OrgMapper orgMapper;

    @Override
    public Result getAllOrg() {
        List<Org> orgs = orgMapper.selectList(null);
        List<OrgParams> orgParamsList = new ArrayList<>();
        for (Org o : orgs) {
            OrgParams orgParams = new OrgParams();
            BeanUtils.copyProperties(o,orgParams);
            orgParamsList.add(orgParams);
        }
        if (orgParamsList.isEmpty()){
            return Result.fail(408,"获取单位为空");
        }
        log.info("查看返回的数据{}",orgParamsList);
        return Result.success(orgParamsList);
    }
}
